package com.guardchina.framework.web.impl;

import com.guardchina.framework.util.exception.login.TokenRefreshException;
import com.guardchina.framework.web.api.TokenValidator;
import com.guardchina.framework.web.model.UserFeature;
import com.guardchina.framework.web.properties.LoginProperties;

/**
 * 描述：token刷新校验
 *
 * @author lwb
 * @date 2019/3/19 15:32
 */
public class TokenRefreshValidator implements TokenValidator {

    private LoginProperties properties;

    public TokenRefreshValidator(LoginProperties properties){
        this.properties = properties;
    }

    @Override
    public void verify(UserFeature userFeature) {
        long currentTime = System.currentTimeMillis();
        if(userFeature.getCreateTime() + properties.getRefreshTime() < currentTime){
            throw TokenRefreshException.error();
        }
    }
}
